package cn.itshare.junit.test;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

import com.share.commons.util.LoadFileUtil;

public class LoadDBInfo {

	public static void main(String[] args) {
		
		try {
			Class.forName("com.mysql.jdbc.Driver") ;
			Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/test","root","saber") ;
			
			DatabaseMetaData md = conn.getMetaData() ;
			
			System.out.println("数据类型:"+md.getDatabaseProductName());
			System.out.println("数据版本:"+md.getDatabaseProductVersion());
			System.out.println("驱动名称"+md.getDriverName());
			System.out.println(md.getURL() );
			conn.close() ;
			System.out.println(Runtime.getRuntime().totalMemory() / (1024.0 * 1024));
			
			Runtime lRuntime = Runtime.getRuntime();
			System.out.println("*******************************");
			System.out.println("最大内存: "+lRuntime.maxMemory()/1024/1024+"M");
			System.out.println("内存总量: "+lRuntime.totalMemory()/1024/1024+"M");
			System.out.println("JVM可用内存: "+lRuntime.freeMemory()/1024/1024+"M");
			System.out.println("可用处理器的数目: "+lRuntime.availableProcessors()+"");
			System.out.println("*******************************");
			
			//虚拟机使用的最大内存量
			double max = (Runtime.getRuntime().maxMemory() / (1024.0 * 1024)) ;
			//虚拟机中的内存总量
			double total = (Runtime.getRuntime().totalMemory() / (1024.0 * 1024)) ;
			//虚拟机中空闲的内存量
			double free = (Runtime.getRuntime().freeMemory() / (1024.0 * 1024)) ;
			
			System.out.println("虚拟机试图使用最大内存量（当前JVM的最大可用内存量）：" + max + "MB");
			System.out.println("虚拟机中的内存总量（当前JVM占用的内存总数）：" + total + "MB");
			System.out.println("虚拟机中的空闲内存量（当前JVM的空闲内存）：" + free + "MB");
			//JVM只有在需要内存时在占用物理内存使用，所以空闲内存(freeMemory)的值一般情况下都很小
			//而JVM实际可用的内存并不等于空闲内存(freeMemory)，而应该等于maxMemory - totalMemory + freeMemory
			System.out.println("实际可用内存量：" +(max - total + free)+ "MB");
			
			Properties p = LoadFileUtil.loadPro("systeminfo.properties") ;
			
			System.out.println(p.getProperty("project.name"));
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		
		
	}
	
}
